/**
 * Copyright (C) 2013-2014 the original author or authors.
 */
package com.foreveross.bsl.push.client;

import java.util.List;

import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.apache.cxf.message.Message;

/**
 * xxx
 *
 * @author Wangyi
 * @version v1.0
 *
 * @date 2013-7-29
 *
 */
public abstract class PushClient {
	
	protected List<?> providers;
	protected List<Interceptor<? extends Message>> outInterceptors;
	protected String targetUrl="http://localhost:18860/push/api";
	
	public <T> T createServiceStub(String address, Class<T> clazz){
		JAXRSClientFactoryBean cfBean=new JAXRSClientFactoryBean();
		cfBean.setAddress(address);
		cfBean.setServiceClass(clazz);
		if(this.outInterceptors!=null){
			cfBean.setOutInterceptors(this.outInterceptors);
		}
		if(this.providers!=null){
			cfBean.setProviders(providers);
		}
		return cfBean.create(clazz);
	}

	/**
	 * @return the providers
	 */
	public List<?> getProviders() {
		return providers;
	}

	/**
	 * @param providers the providers to set
	 */
	public void setProviders(List<?> providers) {
		this.providers = providers;
	}

	/**
	 * @return the targetUrl
	 */
	public String getTargetUrl() {
		return targetUrl;
	}

	/**
	 * @param targetUrl the targetUrl to set
	 */
	public void setTargetUrl(String targetUrl) {
		this.targetUrl = targetUrl;
	}

	/**
	 * @return the outInterceptors
	 */
	public List<Interceptor<? extends Message>> getOutInterceptors() {
		return outInterceptors;
	}

	/**
	 * @param outInterceptors the outInterceptors to set
	 */
	public void setOutInterceptors(List<Interceptor<? extends Message>> outInterceptors) {
		this.outInterceptors = outInterceptors;
	}
	
}
